package com.itheima.day02_delayqueue_consumer;

import com.rabbitmq.client.Channel;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

import java.io.IOException;

@Component
public class RabbitMQListener {

    @RabbitListener(queues = "queue_dlx")
    public void delayListener(Message message, Channel channel) throws IOException {
        long deliveryTag = message.getMessageProperties().getDeliveryTag();
        try {
            System.out.println(new String(message.getBody()));
            channel.basicAck(deliveryTag,true);
        } catch (Exception e) {
            System.out.println("出现异常，拒绝签收");
            channel.basicNack(deliveryTag,true,false);
        }
    }
}
